﻿@page "/inputs"

<h3>Input 输入框</h3>

<h4>通过鼠标或键盘输入字符</h4>

<Block Title="基础用法" Introduction="提供基本的文本录入组件" CodeFile="input.1.html">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <label class="control-label">基本用法</label>
                <BootstrapInput TItem="string" placeholder="请输入 ..."></BootstrapInput>
            </div>
        </div>
    </div>
</Block>

<Block Title="单向绑定数据" Introduction="显示组件内变量值" CodeFile="input.2.html">
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <label class="control-label">单向绑定</label>
                <BootstrapInput TItem="string" placeholder="请输入 ..." Value="@InputValue"></BootstrapInput>
            </div>
        </div>
    </div>
</Block>

<Block Title="双向绑定数据" Introduction="绑定组件内变量，数据自动同步" CodeFile="input.3.html">
    <p><code>BootstrapInput</code> 组件开启双向绑定时，会根据绑定的 <code>Model</code> 属性值去自动获取 <code>DisplayName</code> 标签值并且显示为前置 <code>Label</code>，通过 <code>DisplayText</code> 属性可以自定义显示前置标签，或者通过 <code>ShowLabel</code> 属性关闭前置标签是否显示</p>
    <div class="form-inline">
        <div class="row">
            <div class="form-group col-12">
                <BootstrapInput TItem="string" placeholder="请输入 ..." @bind-Value="@BindValue" DisplayText="双向绑定示例">
                </BootstrapInput>
            </div>
            <div class="form-group col-12">
                <div>绑定数值: @BindValue</div>
            </div>
            <Divider Text="自定义标签" />
            <div class="form-group col-12">
                <p>设置 <code>DisplayText</code> 值为 <b>自定义标签</b></p>
            </div>
            <div class="form-group col-12">
                <BootstrapInput TItem="string" placeholder="请输入 ..." @bind-Value="@BindValue" DisplayText="自定义标签">
                </BootstrapInput>
            </div>
            <Divider Text="占位" />
            <div class="form-group col-12">
                <p>设置 <code>DisplayText</code> 值为 <code>string.Empty</code></p>
            </div>
            <div class="form-group col-12">
                <BootstrapInput TItem="string" placeholder="请输入 ..." @bind-Value="@BindValue" DisplayText="">
                </BootstrapInput>
            </div>
            <Divider Text="不占位" />
            <div class="form-group col-12">
                <p>设置 <code>ShowLabel</code> 为 <code>false</code></p>
            </div>
            <div class="form-group col-12">
                <BootstrapInput TItem="string" placeholder="请输入 ..." @bind-Value="@BindValue" ShowLabel="false">
                </BootstrapInput>
            </div>
        </div>
    </div>
</Block>

<Block Title="客户端验证" Introduction="根据自定义验证规则进行数据有效性检查并自动提示" CodeFile="input.4.html">
    <ValidateForm class="form-inline" Model="@Model">
        <div class="row">
            <div class="form-group col-12">
                <label class="control-label">数据验证</label>
                <BootstrapInput TItem="string" maxlength="5" placeholder="请输入 ..." @bind-Value="@Model.Name">
                    <RequiredValidator />
                    <StringLengthValidator Length="5" />
                </BootstrapInput>
            </div>
        </div>
    </ValidateForm>
</Block>

<Block Title="密码框" Introduction="通过设置属性 <code>IsPassword</code> 值使输入数字后以 <code>*</code> 进行屏蔽的密码输入框" CodeFile="input.5.html">
    <p>为了支持更多的文本框属性本组件可以直接写入 <code>type="email"</code> <code>type="number"</code> <code>type="phone"</code> 等 <code>html5</code> 新标准支持的全部属性值，组件未设置 <code>type</code> 值时使用默认的 <code>type="text"</code>, 仅当未设置 <code>type</code> 属性值时 <code>IsPassword</code> 才生效</p>
    <BootstrapInput TItem="string" IsPassword="true" maxlength="5" placeholder="请输入 ..." style="width: 120px;">
    </BootstrapInput>
</Block>

<AttributeTable Items="@GetAttributes()" />

@code {
    private string InputValue => "数据值";

    private string BindValue { get; set; } = "绑定值";

    private FooModel Model { get; set; } = new FooModel();

    private class FooModel
    {
        [System.ComponentModel.DisplayName("姓名")]
        public string Name { get; set; } = "张三";
    }

    private IEnumerable<AttributeItem> GetAttributes()
    {
        return new AttributeItem[]
        {
            new AttributeItem() {
                Name = "ChildContent",
                Description = "验证控件",
                Type = "RenderFragment",
                ValueList = " — ",
                DefaultValue = " — "
            },
            new AttributeItem() {
                Name = "ShowLabel",
                Description = "是否显示前置标签",
                Type = "bool",
                ValueList = "true|false",
                DefaultValue = "true"
            },
            new AttributeItem()
            {
                Name = "type",
                Description = "控件类型",
                Type = "string",
                ValueList = "text / number / email / url / password",
                DefaultValue = "text"
            },
            new AttributeItem()
            {
                Name = "IsPassword",
                Description = "密码框",
                Type = "bool",
                ValueList = "true|false",
                DefaultValue = "false"
            },
        };
    }
}
